# Maintainer: Sergej Pupykin <arch+pub@sergej.pp.ru>
# Maintainer: Robert Knauer <robert@privatdemail.net>

pkgbase=luadbi
pkgname=(lua51-dbi lua52-dbi lua53-dbi lua-dbi)
pkgver=0.7.2
pkgrel=2
pkgdesc="Database interface library for Lua"
arch=('loong64' 'x86_64')
url="https://github.com/mwild1/luadbi"
license=('MIT')
makedepends=('sqlite3'
             'mariadb-libs'
             'postgresql'
             'lua'
             'lua51'
             'lua52'
             'lua53')
optdepends=('sqlite3: sqlite3 Support'
            'postgresql-libs: postgresql Support'
            'mariadb-libs: mysql Support')
source=("$pkgname-$pkgver.tar.gz::https://github.com/mwild1/luadbi/archive/v$pkgver.tar.gz")
sha512sums=('891f99cbc8f1b5327ef820641a1608abf41410f2f28584b975cc3cf65154b9bebf6f1b9ca7d1818b9c965738ad700dd17ae042dfd2a7146cf755871ebae535b9')

prepare() {
  cp -r "$srcdir"/luadbi-$pkgver "$srcdir"/luadbi51-$pkgver
  cp -r "$srcdir"/luadbi-$pkgver "$srcdir"/luadbi52-$pkgver
  cp -r "$srcdir"/luadbi-$pkgver "$srcdir"/luadbi53-$pkgver
}

build() {
  cd "$srcdir/luadbi51-$pkgver"
  make free LUA_V=5.1

  cd "$srcdir/luadbi52-$pkgver"
  make free LUA_V=5.2

  cd "$srcdir/luadbi53-$pkgver"
  make free LUA_V=5.3

  cd "$srcdir/luadbi-$pkgver"
  make free LUA_V=5.4
}

package_lua51-dbi() {
  cd "$srcdir/luadbi51-$pkgver"
  make install_free DESTDIR="$pkgdir" LUA_V=5.1
  install -Dm644 COPYING "${pkgdir}/usr/share/licenses/${pkgname}/COPYING"
}

package_lua52-dbi() {
  cd "$srcdir/luadbi52-$pkgver"
  make install_free DESTDIR="$pkgdir" LUA_V=5.2
  install -Dm644 COPYING "${pkgdir}/usr/share/licenses/${pkgname}/COPYING"
}

package_lua53-dbi() {
  cd "$srcdir/luadbi53-$pkgver"
  make install_free DESTDIR="$pkgdir" LUA_V=5.3
  install -Dm644 COPYING "${pkgdir}/usr/share/licenses/${pkgname}/COPYING"
}

package_lua-dbi() {
  cd "$srcdir/luadbi-$pkgver"
  make install_free DESTDIR="$pkgdir" LUA_V=5.4
  install -Dm644 COPYING "${pkgdir}/usr/share/licenses/${pkgname}/COPYING"
}
